package com.hsogoo.study.spring.beanfactorypostprocessor;

import java.util.Date;

import org.junit.Test;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.annotation.Import;

/**
 * Created by za-huangsaigang on 2018/9/17.
 */
@Configuration
@Import({User.class})
public class ConfigurationClassPostProcessorTest {

    @Bean
    Date date() {
        return new Date();
    }

    @Test
    public void testConfigurationClassPostProcessor(){
        ConfigurationClassPostProcessor postProcessor = new ConfigurationClassPostProcessor();
        SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
        registry.registerBeanDefinition("test", new RootBeanDefinition(ConfigurationClassPostProcessorTest.class));
        //处理BeanDefinitionRegistry
        postProcessor.postProcessBeanDefinitionRegistry(registry);

        //输出结果
        System.out.println(registry.getBeanDefinition("test"));//可以输出
        System.out.println(registry.getBeanDefinition("date"));//可以输出
        System.out.println(registry.getBeanDefinition("com.hsogoo.study.spring.beanfactorypostprocessor.User"));//可以输出
    }

}
